package com.heima.article.controller;

import com.heima.article.service.ApArticleService;
import com.heima.model.article.constant.ArticleConstants;
import com.heima.model.article.dots.ArticleHomeDto;
import com.heima.model.common.dtos.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/v1/article")
public class ArticleHomeController {

    @Autowired
    private ApArticleService apArticleService;

    /**
     * 初始加载数据
     * @return
     */
    @PostMapping("/load")
    public ResponseResult loadInit(@RequestBody ArticleHomeDto articleHomeDto){
        ResponseResult load = apArticleService.load(articleHomeDto, ArticleConstants.OPERTATION_LOAD_MORE);
        return   load;
    }

    //加载更多
    @PostMapping("/loadmore")
    public ResponseResult loadMore(@RequestBody ArticleHomeDto articleHomeDto){
        return  apArticleService.load(articleHomeDto , ArticleConstants.OPERTATION_LOAD_MORE ) ;
    }

    //加载最新
    @PostMapping("/loadnew")
    public ResponseResult loadnew(@RequestBody ArticleHomeDto articleHomeDto){
        return  apArticleService.load(articleHomeDto , ArticleConstants.OPERTATION_LOAD_NEW ) ;
    }

}
